﻿using Orchard.ContentManagement;
using Orchard.Data;
using Orchard.Logging;
using Orchard.Services;
using Utils.WidgetInserter.Models;
using Utils.WidgetInserter.Services;

namespace Utils.WidgetInserter.Filters
{
    public class HtmlFilter : IHtmlFilter {
        private readonly IContentManager _contentManager;
        private readonly IRepository<SettingsPartRecord> _repository;
        private readonly ISettingsService _settingsService;

        public ILogger Logger { get; set; }

        public HtmlFilter(IContentManager contentManager, IRepository<SettingsPartRecord> repository, ISettingsService settingsService)
        {
            _contentManager = contentManager;
            _repository = repository;
            _settingsService = settingsService;
            Logger = NullLogger.Instance;
        }

        public string ProcessContent(string text, string flavor)
        {
            var widgetParser = new WidgetParser(Logger);
            return widgetParser.Replace(text, _contentManager, _settingsService);
        }
    }
}